﻿// <copyright file="IntExtensionsTests.cs" company="Fluent.NET">
// Microsoft Public License (Ms-PL)
// </copyright>
// <author>Chris Eargle</author>
// <email>kodefuguru@live.com</email>
// <date>2009-12-09</date>
// <summary>IntExtenions tests</summary>
namespace Fluent.Tests
{
    using System.Linq;
    using Fluent;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Tests for IntExtensions
    /// </summary>
    [TestClass]
    public class IntExtensionsTests
    {
        /// <summary>
        /// Tests returning a sequence from one number to another.
        /// </summary>
        [TestMethod]
        public void CountUp()
        {
            var numbers = 5.To(9);
            Assert.IsTrue(numbers.Any(n => n > 4));
            Assert.IsFalse(numbers.Any(n => n < 5));
            Assert.AreEqual(5, numbers.Count());
            Assert.AreEqual(5, numbers.First());
        }

        /// <summary>
        /// Tests returning a sequence from one number down to another.
        /// </summary>
        [TestMethod]
        public void Countdown()
        {
            var numbers = 9.To(5);
            Assert.IsTrue(numbers.Any(n => n > 4));
            Assert.IsFalse(numbers.Any(n => n < 5));
            Assert.AreEqual(5, numbers.Count());
            Assert.AreEqual(9, numbers.First());
        }

        /// <summary>
        /// Tests returning a sequence of a single number.
        /// </summary>
        [TestMethod]
        public void Single()
        {
            var numbers = 1.To(1);
            Assert.AreEqual(1, numbers.Single());
        }

        /// <summary>
        /// Tests returning a sequence from one down to 0.
        /// </summary>
        [TestMethod]
        public void DownToZero()
        {
            var numbers = 1.To(0);
            Assert.AreEqual(2, numbers.Count());
        }

        /// <summary>
        /// Tests returning a sequence from one number to another over 0.
        /// </summary>
        [TestMethod]
        public void CrossoverZero()
        {
            var numbers = (-5).To(5);
            Assert.AreEqual(11, numbers.Count());
            Assert.AreEqual(-5, numbers.First());
            Assert.AreEqual(5, numbers.Last());
        }

        /// <summary>
        /// Tests returning a sequence from one number down to another over zero.
        /// </summary>
        [TestMethod]
        public void CrossoverZeroDown()
        {
            var numbers = 5.To(-5);
            Assert.AreEqual(11, numbers.Count());
            Assert.AreEqual(5, numbers.First());
            Assert.AreEqual(-5, numbers.Last());
        }
    }
}
